网站首页
联系我们
站内搜索
网站首页源码下载站长教程编程开发电脑教程网址导航网络文学

网站制作

本类阅读TOP10

·IIS 安装配置全攻略
·用VS.NET打开网上下载的.NET web项目出错的解决办法
·HTML 4.0 语言快速参考
·限制TextArea区的文字输入数量
·如何在网页上实现进度条
·Apache的配置步骤及测试
·谈谈Jesse James Garrett提到的Ajax
·html基础学习笔记(2)
·页面垂直居中的两种方法
·用asp遍历目录下文件的例子

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
如何 Encode 和 Decode URL 地址?

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

这个问题比较热门的说~ASP 的 Server 对象提供了一个 Server.Encode() 方法,但是却没有相应的 Server.Decode() 方法或者 Unencode() 方法 >_< 也许 M$ 认为这没必要……大错特错啊。这样的方法非常有用,这里提供一种实现~包括 VBScript 和 JScript 代码。

VBScript

<% 
    Function URLDecode(str)
        str = Replace(str, "+", " ")
        For i = 1 To Len(str)
            sT = Mid(str, i, 1)
            If sT = "%" Then
                If i+2 < Len(str) Then
                    sR = sR & _
                        Chr(CLng("&H" & Mid(str, i+1, 2)))
                    i = i+2
                End If
            Else
                sR = sR & sT
            End If
        Next
        URLDecode = sR
    End Function

    Function URLEncode(str)
        URLEncode = Server.URLEncode(str)
    End Function

    str1 = "http://www.foo.com/blah.asp?foo=1 & 2 &g=0"
    str2 = URLEncode(str1)
    str3 = URLDecode(str2)
    Response.Write(str1 & "<br>" & str2 & "<br>" & str3)
%>
JScript
<script language=JScript runat=server> 

    function URLDecode(str)
    {
        return unescape(str);
    }

    function URLEncode(str)
    {
        str = escape(str);

        // JScript doesn't think '/' needs to be escaped...
        // I'm not sure it does either, but take it out to be
        // consistent with VBScript's built-in URLEncode()

        while (str.indexOf("/")!=-1)
        {
            str = str.replace("/","%2F");
        }
        return str;
    }

    var str1 = "http://www.foo.com/blah.asp?foo=1 & 2 &g=0";
    var str2 = URLEncode(str1);
    var str3 = URLDecode(str2);
    Response.Write(str1 + "<br>" + str2 + "<br>" + str3)
</script>
转自:http://dotnet.btobcn.net/Article_Detail.aspx?Aid=75



相关文章

相关软件




月光软件站·版权所有 粤ICP备16102788号-2